package com.zcxy360.sandtable.util;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;

public class MessageUtil {
	
	public static final Map<String,String> CODE_CACHE = new ConcurrentHashMap<>();

	public static boolean sendCode(String phone) {
		boolean flag = false;
		String code = new Random().nextInt(899999) + 100000 + "";
		TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "23334365",
				"3d4b1f76516cf61f5ffbd2c80d13e363");
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
		req.setExtend(code);
		req.setSmsType("normal");
		req.setSmsFreeSignName("身份验证");
		req.setSmsParamString("{\"code\":\"" + code + "\",\"product\":\"系统\"}");
		req.setRecNum(phone);
		req.setSmsTemplateCode("SMS_6690684");
		try {
			client.execute(req);
			CODE_CACHE.put(phone, code);
			flag = true;
		} catch (ApiException e1) {
			e1.printStackTrace();
		}
		return flag;
	}

}
